package template;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class jiaojiString {
    public static void main(String[] args) {
        //m1();两个字符串的交集，如aabd和abbffec的交集是ab

    }

    private static void m1() {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            int count = 0, max = 0, end = 0;
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
                    count++;
                    if (max < count) {
                        max = count;
                        end = i;
                    }
                } else {
                    count = 0;
                }
            }
//substring(a,b)包含a不包含b。假设刚开始有3个数字，end=2而max=3，a为0，所以end-max+1
            System.out.println(str.substring(end - max + 1, end + 1));
        }
    }

    private static String run1(String s1, String s2) {
        StringBuilder res = new StringBuilder();
        Set<Character> set1 = new HashSet<>();
        for (char c : s1.toCharArray()) {
            set1.add(c);
        }
        Set<Character> set2 = new HashSet<>();
        for (char c : s2.toCharArray()) {
            set2.add(c);
        }
        for (char c : set1) {
            if (set2.contains(c)) {
                res.append(c);
            }
        }
        return res.toString();
    }

    private static String run2(String s1, String s2) {
        StringBuilder res = new StringBuilder();
        Set<Character> set1 = new HashSet<>();
        for (char c : s1.toCharArray()) {
            set1.add(c);
        }
        Set<Character> set2 = new HashSet<>();
        for (char c : s2.toCharArray()) {
            set2.add(c);
        }
        for (char c : set1) {
            if (set2.contains(c)) {
                res.append(c);
            }
        }
        return res.toString();
    }

    public static void checkCommom(String str1, String str2) {

        HashSet<String> result = new HashSet<String>();
        int length1 = str1.length();
        int length2 = str2.length();
        for (int i = 0; i < length1; i++) {
            for (int j = 0; j < length2; j++) {
                String char1 = str1.charAt(i) + "";
                String char2 = str2.charAt(j) + "";
                if (char1.equals(char2)) {
                    result.add(char1);
                }
            }
        }

        Iterator<String> it = result.iterator();
        while (it.hasNext()) {
            String value = it.next();
            System.out.print(value);
        }
    }
}
